<template>
  <div class="m-order-common">
    <!-- E店宝同步 -->

    <!-- 搜索 -->
    <div class="order-search-tab">
      <div class="o">
        <span class="title">订单编号</span>
        <div class="input dis-block">
          <w-input holder="请填写" v-model="cParams.tid"></w-input>
        </div>
      </div>
      <!-- 操作按钮 -->
      <div class="order-options">
        <w-button-group>
          <w-button type="main" @on-click="fetchCOrderListSearch">搜索订单</w-button>
        </w-button-group>
      </div>
    </div>
    <!-- 订单列表 -->
    <div class="m-order-lists">
      <!-- 订单列表组件 -->
      <div>
        <div style="margin-bottom: 20px;">
          <w-table :columns="columns"></w-table>
        </div>
        <div v-if="orderList.recordList && orderList.recordList.length">
          <!-- 列表 -->
          <div v-for="(order, orderIndex) in orderList.recordList" :key="orderIndex"> 
            <div class="lists">
              <div class="order-item" >
                <table class="m-order-table clearfix">
                  <tr>
                    <th class="order-title" colspan="6">
                      <div class="c-h-l fl">
                        <div class="check-box">
                          <!-- <w-checkbox :label="`order${orderIndex}`" name="订单" v-model="order.checked" @on-change="_setStoreToAllCheck"></w-checkbox> -->
                        </div>
                        <span>订单编号：<span style="color: #2576FF">{{order.tid}}</span></span>
                        <span style="margin-left: 20px;">下单时间：{{order.getTime || '暂无'}}</span>
                      </div>
                    </th>
                  </tr>
                </table>
                <!-- 列表 -->  
                <div class="clearfix order-list">
                  <table style="width: 48%" class="fl">
                    <tbody v-for="(order, goodsIndex) in JSON.parse(order.goodsInfo || '[]')" :key="goodsIndex">
                      <tr class="bor-b" v-for="(gsp, gspIndex) in order.goodsGsp" :key="gspIndex">
                        <td class="clearfix goods-list" style="width: 28%">
                          <!-- 缺货标记：out-stock -->
                          <div class="fl goods-main-img">
                            <img v-lazy="order.goods_mainphoto_path" alt="">
                          </div>
                          <div class="goods-info">
                            <p class="p-line-hide">{{order.goods_name}}</p>
                            <!-- SKU -->
                            <div class="goods-sku txt-goods" v-if="gsp.goodsSpecContent">
                              <span>{{gsp.goodsSpecContent.substring(0, 1) == '[' ? gsp.goodsSpecContent.substring(1, gsp.goodsSpecContent.length - 1) : gsp.goodsSpecContent}} </span>
                              <!-- <span style="margin-left: 16px">{{gsp.goodsSpecName[1]}}：{{gsp.goodsSpecContent.substring(1, gsp.goodsSpecContent.length -1).split(',')[1]}}</span> -->
                              <br>
                              <span>商品编码：{{order.goodsSerial}}</span>
                            </div>
                          </div>
                        </td>
                        <!-- 单价，数量 -->
                        <td style="width: 12%;" class="goods-del">
                          <span class="txt-goods number">￥{{(gsp.goodsSinglePrice || 0) | currency}}</span>
                          <div class="number">
                            <span class="txt-goods goods-count">{{gsp.count}}</span>
                          </div>
                        </td>
                      </tr>
                    </tbody>
                  </table>

                  <!-- 状态，操作等 -->
                  <table style="width: 52%" class="fr" :style="{'height': tabHeight(order)}">
                    <tbody>
                      <tr>
                        <!-- 购买人 -->
                        <td style="width: 14%" class="buyer txt-m" rowspan="2">
                          <span>{{order.receiver_mobile}}</span>
                          <br>
                          <span>{{order.mobile}}</span>
                        </td>
                        <!-- 交易状态 -->
                        <td style="width: 14%" class="options td-top" rowspan="2">
                          <!-- <span class="c-main">{{order.order_status == 30 ? '已付款' : order.order_status == 40 ? '待收货 ' : '确认收货' }}</span> -->
                          <span class="c-main" v-if="order.order_status == 30">已付款</span>
                          <span class="c-main" v-if="order.order_status == 40">待收货</span>

                          <span class="c-main" v-if="order.order_status == 10">等待买家付款</span>
                          <span class="c-main" v-if="order.order_status == 13">贷款成功</span>
                          <span class="c-main" v-if="order.order_status == 16">货到付款</span>
                          <span class="c-main" v-if="order.order_status == 20 || order.refundStatus == 2">待发货</span>
                          <span class="c-main" v-if="order.order_status == 21 || order.refundStatus == 0">退款待审核</span>
                          <span class="c-main" v-if="order.order_status == 22 || order.refundStatus == 1">退款审核中</span>
                          <span class="c-main" v-if="order.order_status == 25 || order.refundStatus == 3">退款成功</span>
                          <span class="c-main" v-if="order.order_status == 23">农商行部分退款中</span>
                          <!-- <span class="c-main" v-if="order.order_status == 30">待收货</span> -->
                          <!-- <span class="c-main" v-if="order.order_status == 40">待评价</span> -->
                          <span class="c-main" v-if="order.order_status == 41">退货申请</span>
                          <span class="c-main" v-if="order.order_status == 42">退货审核中</span>
                          <span class="c-main" v-if="order.order_status == 45">退货成功</span>
                          <span class="c-main" v-if="order.order_status == 46">退款及退货退款</span>
                          <span class="c-main" v-if="order.order_status == 50">交易成功</span>
                          <span class="c-main" v-if="order.order_status == 65">系统自动好评</span>
                          <br>
                          <span class="det cur" @click="onJumpDetail(order.id, order.reId)">详情</span>
                        </td>
                        <!-- 实收款 -->
                        <td style="width: 14%" class="goods-amount td-top operate" rowspan="2" :class="{ remind: order.remindDeliver == 1 }">
                          <span class="amount">¥{{order.order_totalfee  | currency}}</span>
                          <br>
                          <span style="color: #999">（含运费：¥{{ (order.real_income_freight || 0) | currency}}）</span>
                          <br>
                          <span>{{order.sending_type}}</span>
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div style="text-align: center; margin: 20px" v-else>
          <p>暂无数据</p>
        </div>
      </div>
    </div>

    <!-- 分页 -->
    <div class="pages" v-if="orderList.pageCount > 1">
      <w-paging :current="orderList.currentPage" :total="orderList.pageCount" @on-page="onChangePage"></w-paging>
    </div>

  </div>
</template>

<script>
// 订单状态列表 
import { apiOrderMange } from 'js/api'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      orderIndex: [],
      order: [],
      columns: [
        {title: '货品', width: '26%'},
        {title: '单价', width: '7%'},
        {title: '数量', width: '7%'},
        {title: '买家', width: '14%'},
        {title: '交易状态', width: '14%'},
        {title: '实收款', width: '14%'}
      ],
      // 普通订单列表参数
      cParams: {
        tid: '', // 订单编号
        currentPage: 1,
        showCount: 20
      },
      orderList: {}
    }
  },
  created() {
    this.fetchCOrderList()
  },
  computed: {
    ...mapGetters(['token'])
  },
  methods: {
    // 计算当前的订单列表高度
    tabHeight(order) {
      let len = 0
      const gList = JSON.parse(order.goodsInfo || '[]')
      if (gList && gList.length) {
        gList.forEach(goods => {
          len += goods.goodsGsp.length
        })
      }
      return `${len * 112}` + 'px'
    },
    /**
     * 获取订单列表
     */
    fetchCOrderList() {
      let _this = this
      // 获取普通订单列表
      apiOrderMange.apieSynchronizedList(this.cParams).then(data => {
        _this.orderList = data.data || {}
      })
    },
    /**
     * 搜索，重置入参
     */
    fetchCOrderListSearch() {
      this.cParams.currentPage = 1
      this.fetchCOrderList()
    },
    /**
     * 分页
     */
    onChangePage(page) {
      this.cParams.currentPage = page
      this.fetchCOrderList()
    },
    /**
     * 查看订单详情
     */
    onJumpDetail(orderId, reId) {
      let reid
      if (reId) {
        reid = reId
      } else {
        reid = ''
      }
      this.$router.push(`../orderMange/synchronizeddetails/${orderId}?three=${this.$route.query.three}&reid=${reid}&isEStore=true`)
    }
  }
}
</script>

<style lang="scss">
.m-order-common {
  .datepicker {
    width: 142px;
    height: 28px;
  }
  .form-control {
    height: 28px !important;
    background-color: #ffffff !important;
    border-radius: 0 !important;
  }
  .order-options {
    .btn {
      width: 170px !important;
    }
  }
  .btns-group {
    .btn {
      width: 60px !important;
    }
  }
  .pages {
    .m-paging {
      text-align: right !important
    }
  }
  .m-confirm-sign {
    .text-area {
      .form-control {
        height: 90px!important;
      }
      .w-input .error-tip {
        top: 56px;
      }
    }
  }
  .p-order-list {
    .w-input .error-tip {
      width: 100%
    }
  }
}
</style>

<style lang="scss" scoped>
.m-confirm-sign {
  // text-align: center;
  .sign {
    margin-bottom: 20px;
  }
  .title {
    width: 80px;
    display: inline-block;
    text-align: right;
    font-size: 12px;
  }
  .info {
    width: 300px;
    margin-left: 10px;
    display: inline-block;
  }
  .radio {
    text-align: left;
    width: 100%;
    margin-top: 10px;
  }
  .flag {
    display: inline-block;
    margin-right: 3%;
    img {
      width: 14px;
      height: 14px;
    }
  }
}
.m-order-lists {
  margin-top: 20px;
}
.order-search-tab {
  margin-top: 20px;
  .title {
    width: 56px;
    text-align: right;
    display: inline-block;
    margin-right: 10px;
    font-size: 12px
  }
  .icon {
    padding: 0 10px;
  }
  .dis-block {
    display: inline-block;
  }
  .date {
    width: 170px;
    display: inline-block;
    vertical-align: middle;
  }
  .o {
    margin-right: 40px;
    margin-bottom: 20px;
    display: inline-block;
  }
  .select {
    width:142px;
    height:28px; 
    vertical-align: middle;
  }
  .o-select {
    width: 170px;
    height: 28px;
  }
  .input {
    width: 170px;
    vertical-align: middle;
  }
  .order-options {
    margin: 48px auto 20px;
    text-align: center;
  }
}
.retact {
  text-align: center;
  color: #9B9B9B;
  padding-bottom: 5px;
  border-bottom: 1px solid #D7D7D7;
  font-size: 10px;
  .icon-arrow {
    width: 10px;
    height: 5px;
    background: url(../../assets/shouqi.png) no-repeat;
    background-size: 100% 100%;
    display: inline-block;
    margin-bottom: 2px;
  }
  .arrow-actived {
    transform: rotate(-180deg)
  }
}
.list-options {
  padding: 14px 0 14px 5px;
  .check-box {
    display: inline-block;
    margin-right: 10px;
    line-height: 22px;
    .all {
      padding-left: 10px;
    }
  }
  .btns-group {
    display: inline-block;
    margin-right: 30px;
  }
}
.order-item {
  margin-bottom: 10px;
}
.m-order-table {
  width: 100%;
}
.order-title {
  width: 100%;
  height: 40px;
  line-height: 40px;
  background-color: #F2F2F2;
  border: 1px solid #DBDBDB;
  padding: 0 20px 0 8px;
  & >div {
    display: inline-block;
  }
  .check-box {
    display: inline-block;
    margin-right: 10px;
    line-height: 22px;
  }
  .c-h-r {
    margin-left: 40px;
    position: relative;
  }
  .store-name {
    font-weight: bold
  }
  .flag {
    width: 14px;
    height: 14px;
    display: inline-block;
    margin-left: 20px;
  }
  .print-btn {
    position: absolute;
    right: 30px;
    top: 5px;
    width: 60px;
  }
}
.goods-main-img {
  width: 88px;
  height: 88px;
  margin-right: 14px;
  position: relative;
}
.bor-b {
  border-bottom: 1px solid #DBDBDB;
}
.goods-list { 
  padding: 12px 10px;
}
.goods-main-img {
  width: 88px;
  height: 88px;
  margin-right: 14px;
  position: relative;
}
.goods-info {
  height: 90px;
  position: relative;
  .goods-sku {
    display: inline-block;
    vertical-align: bottom;
    position: absolute;
    color: #999999;
    bottom: 0;
    & > span {
      line-height: 20px;
    }
  }
}
.order-list {
  border: 1px solid #DBDBDB;
  border-top: none;
  table {
    tbody {
      &:last-child {
        tr {
          &:last-child {
            border-bottom: none
          }
        }
      }
    }
  }
}
.det {
  color: #2D8EFE;
  text-decoration: underline;
}
.goods-del {
  padding: 50px 5px;
  text-align: center;
  border-left: 1px solid #DBDBDB;
  border-right: 1px solid #DBDBDB;
}
.buyer {
  padding: 50px 5px;
  text-align: center;
  color: #313131;
  border-right: 1px solid #DBDBDB
}
.goods-amount {
  text-align: center;
  padding: 30px;
  border-right: 1px solid #DBDBDB;
}
.options {
  text-align: center;
  border-right: 1px solid #DBDBDB;
}
.txt-m {
  color: #313131
}
.goods-del .number {
  width: 42%;
  display: inline-block;
}
.goods-del .goods-count {
  border: 1px solid #DBDBDB;
  padding: 5px 10px;
  margin: 0 20px 0 16px;
}
</style>
